var CONTEXT_PATH = function() { 
    var root = window.top.location.href.replace("http://","").replace("https://","").replace("//","/");   
    var first = root.indexOf("/");   
    root = root.substr(first, root.indexOf("/",first+1) - first);   
    return root;
}();
var CONTEXT_HEAD = function() { 
    var root = window.top.location.href.replace("http://","").replace("https://","").replace("//","/");   
    var first = root.indexOf("/");   
    root = root.substr(0, first+1);   
    return "http://"+root;
}();
unopen = function() {
	alert("暂未开放！");
};
request = function(paras) {
	var url = window.location.href;
	var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
	var paraObj = {};
	for(var i = 0; j = paraString[i]; i++) {
		paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
	}
	var returnValue = paraObj[paras.toLowerCase()];
	if( typeof (returnValue) == "undefined") {
		return "";
	} else {
		return returnValue;
	}
};
//设置cookie
setCookies = function(cookieName, cookieValue) {
	var Hours = 10;
	//此 cookie 将被保存 10个小时
	var exp = new Date();
	exp.setTime(exp.getTime() + Hours * 60 * 60 * 1000);
	document.cookie = cookieName + "=" + escape(cookieValue) + ";path=/;expires=" + exp.toGMTString();
};
//获取cookie
getCookies = function(cookieName) {
	var arr = document.cookie.match(new RegExp("(^| )" + cookieName + "=([^;]*)(;|$)"));
	if(arr != null) {
		return unescape(arr[2]);
	}
	return "";
};
//删除cookie
delCookies = function(cookieName) {
	var exp = new Date();
	exp.setTime(exp.getTime() - 1000);
	document.cookie = cookieName + "=0; expires=" + exp.toGMTString();
};

var GLOBAL = {
	"WEEK_NAME": new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"),
	"WEEK_VALUE": new Array(1, 2, 3, 4, 5, 6, 7),
	"WEEK_SHOW": new Array("一", "二", "三", "四", "五", "六", "日"),
	"BOX_AREA": null,
	"BOX_SYS_POSITION": null,
	"BOX_SYS_TYPE": null
};
	
GLOBAL.getAreaMatchList = function(){
	var _data = null;
	$.ajax({
		async: false,
		type : "get",
		url : "/common/match/area",
		cache : false,
		dataType : "json"
	}).done(function(result){
		if(result.isTrue) {
			_data = result.items;
		} else {
			$.messager.alert('提示信息', result.message);
		}
	}).fail(function(){
		$.messager.alert('提示信息', "网络繁忙，请稍后再试！");
	});
	if(_data==null) {
		return [{"text":"请求失败", "value":""}];
	} else {
		return _data;
	}
};
	
GLOBAL.getSysPositionMatchList = function(){
	var _data = null;
	$.ajax({
		async: false,
		type : "get",
		url : "/common/match/ad/position",
		cache : false,
		dataType : "json"
	}).done(function(result){
		if(result.isTrue) {
			_data = result.items;
		} else {
			$.messager.alert('提示信息', result.message);
		}
	}).fail(function(){
		$.messager.alert('提示信息', "网络繁忙，请稍后再试！");
	});
	if(_data==null) {
		return [{"text":"请求失败", "value":""}];
	} else {
		return _data;
	}
};
	
GLOBAL.getSysTypeMatchList = function(){
	var _data = null;
	$.ajax({
		async: false,
		type : "get",
		url : "/common/match/ad/type",
		cache : false,
		dataType : "json"
	}).done(function(result){
		if(result.isTrue) {
			_data = result.items;
		} else {
			$.messager.alert('提示信息', result.message);
		}
	}).fail(function(){
		$.messager.alert('提示信息', "网络繁忙，请稍后再试！");
	});
	if(_data==null) {
		return [{"text":"请求失败", "value":""}];
	} else {
		return _data;
	}
};
	
GLOBAL.getOwnerMatchList = function(){
	var _data = null;
	$.ajax({
		async: false,
		type : "get",
		url : "/common/match/owner",
		cache : false,
		dataType : "json"
	}).done(function(result){
		if(result.isTrue) {
			_data = result.items;
		} else {
			$.messager.alert('提示信息', result.message);
		}
	}).fail(function(){
		$.messager.alert('提示信息', "网络繁忙，请稍后再试！");
	});
	if(_data==null) {
		return [{"text":"请求失败", "value":""}];
	} else {
		return _data;
	}
};

GLOBAL.getAdMatchList = function(hasAll){
	var _data = null;
	$.ajax({
		async: false,
		type : "get",
		url : "/common/match/ad",
		cache : false,
		dataType : "json"
	}).done(function(result){
		if(result.isTrue) {
			_data = result.items;
			if(hasAll) {
				_data.push({"text":"全部广告", "value":""});
			}
		} else {
			$.messager.alert('提示信息', result.message);
		}
	}).fail(function(){
		$.messager.alert('提示信息', "网络繁忙，请稍后再试！");
	});
	if(_data==null) {
		return [{"text":"请求失败", "value":""}];
	} else {
		return _data;
	}
};

GLOBAL.getCompanyMatchList = function(hasAll){
	if(window.localStorage.getItem("adminRoleName")!="超级管理员") {
		return [{"text":"暂无权限", "value":""}];
	}
	var _data = null;
	$.ajax({
		async: false,
		type : "get",
		url : "/common/match/company",
		cache : false,
		dataType : "json"
	}).done(function(result){
		if(result.isTrue) {
			_data = result.items;
			if(hasAll) {
				_data.push({"text":"全部公司", "value":""});
			}
		} else {
			$.messager.alert('提示信息', result.message);
		}
	}).fail(function(){
		$.messager.alert('提示信息', "网络繁忙，请稍后再试！");
	});
	if(_data==null) {
		return [{"text":"请求失败", "value":""}];
	} else {
		return _data;
	}
};


/*
 *获取中文长度,一个中文相当于两个英文
 */
String.prototype.CHNLength = function(){
    return this.replace(/[^\x00-\xFF]/g, '**').length;
};
/*
 * 去除字符串两端空格
 */
String.prototype.trim = function(){
	if(this==null) return "";
	else return $.trim(this);
};
/*
 将字符串中的空格去掉
 **/
String.prototype.deleteSpace = function(){
    return this.replace(/\s/g, "");
};

/**
 * 转换数字到日期字符串
 * @param {Object} type	1:"yyyy-MM-dd HH:mm:ss"; 2:"yyyy-MM-dd HH:mm"; 3:"yyyy-MM-dd"; 4:"yyyy-MM"; 5:"array"
 */
Number.prototype.date = function(type){
	if(isNaN(this) || this==null || this=="") {
		return "";
	}
	var date = new Date(this);
	var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var hour = date.getHours();
    var min = date.getMinutes();
    var sec = date.getSeconds();
    if (month < 10) 
        month = "0" + month;
    if (day < 10) 
        day = "0" + day;
    if (hour < 10) 
        hour = "0" + hour;
    if (min < 10) 
        min = "0" + min;
    if (sec < 10) 
        sec = "0" + sec;
    switch(type) {
    	case 1:
    		return year + "-" + month + "-" + day + " " + hour + ":" + min + ":" + sec;
    	case 2:
			return year + "-" + month + "-" + day + " " + hour + ":" + min;
    	case 3:
			return year + "-" + month + "-" + day;
    	case 4:
			return year + "-" + month;
    	case 5:
			return new Array(year, month, day, hour, min, sec);
		default:
    		return year + "-" + month + "-" + day + " " + hour + ":" + min;
    }
};
/**
 * 转换字符串到日期对象
 * @param {Object} type 1:"yyyy-MM-dd"; 2:"yyyy-MM-dd HH:mm"; 
 */
String.prototype.toDate = function(type){
    switch(type) {
    	case 1:
			var y_m_d = this.split("-");
			return new Date(y_m_d[0], (parseInt(y_m_d[1], 10)-1), y_m_d[2]);
    	case 2:
    		var y_m_d = this.split(" ")[0].split("-");
    		var h_m = this.split(" ")[1].split(":");
			return new Date(y_m_d[0], (parseInt(y_m_d[1], 10)-1), y_m_d[2], h_m[0], h_m[1]);
		default:
    		var y_m_d = this.split(" ")[0].split("-");
    		var h_m = this.split(" ")[1].split(":");
			return new Date(y_m_d[0], (parseInt(y_m_d[1], 10)-1), y_m_d[2], h_m[0], h_m[1]);
    }
};
String.prototype.betweenTime = function(){
	var target = this.toDate();
	var between = target.getTime() - new Date().getTime();
	if(between<0) {
		return "已过期";
	}
	return between.duration();
};
Number.prototype.duration = function(){
	var between = this;
	var day = 0, hour = 0, min = 0, second = 0;
	if(between>=3600*24*1000) {
		day = parseInt(between/(3600*24*1000));
		between = between - day*3600*24*1000;
	}
	day = day==0?"":day+"天";
	if(between>=3600*1000) {
		hour = parseInt(between/(3600*1000));
		between = between - hour*3600*1000;
	} 
	hour = (hour==0&&day=="")?"":hour+"小时";
	if(between>60000) {
		min = parseInt(between/60000);
		between = between - min*60000;
	}
	min = (min==0&&hour==0&&day=="")?"":min+"分钟";
	if(between>1000) {
		second = parseInt(between/1000);
	}
	second = (second==0?1:second)+"秒";
	return day+hour+min+second;
};
Number.prototype.objEdit = function(id){
	if(this==getCookies("userSector")) {
		return "<a class=\"edit\" onclick=\"editObjShow('"+id+"');\">编辑</a>";
	}
	return "";
};
Number.prototype.objState = function(id, belongSector){
	if(belongSector!=getCookies("userSector")) {
		return "<a class=\"finish\">暂无</a>";
	}
	if(this==1) {
		return "<a class=\"del\" onclick=\"delObj('"+id+"');\">删除</a>";
	} else if (this==9) {
		return "<a class=\"restore\" onclick=\"restoreObj('"+id+"');\">恢复</a>";
	} else {
		return "<a class=\"finish\">暂无</a>";
	}
};
	

String.prototype.sendTime = function(msgType, addTime){
	switch(msgType) {
		case "00":
			return addTime.date();
		case "01":
			return this.replace("_", " ");
		case "02":
			var result = "星期";
			var day = this.split("_")[0].split(",");
			for(var i=0; i<day.length; i++){
				result+=GLOBAL.WEEK_SHOW[day[i]];
			}
			return result+"的"+this.split("_")[1];
		default:
			return "";
	}
};



// A more performant, but slightly bulkier, RFC4122v4 solution.  We boost performance
// by minimizing calls to random()
Math.uuid = function() {
	var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''), uuid = new Array(36), rnd = 0, r;
	for(var i = 0; i < 36; i++) {
		if(i == 8 || i == 13 || i == 18 || i == 23) {
			uuid[i] = '-';
		} else if(i == 14) {
			uuid[i] = '4';
		} else {
			if(rnd <= 0x02)
				rnd = 0x2000000 + (Math.random() * 0x1000000) | 0;
			r = rnd & 0xf;
			rnd = rnd >> 4;
			uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
		}
	}
	return uuid.join('');
};

//JSON.stringify(jsonObj)
//eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([235-9ehlmo-qw-zA-EG-SU-Y]|1\\w)'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('3(!l.m){m={}}(5(){5 f(n){7 n<10?\'0\'+n:n}3(6 13.w.q!==\'5\'){13.w.q=5(h){7 l.getUTCFullYear()+\'-\'+f(l.getUTCMonth()+1)+\'-\'+f(l.getUTCDate())+\'T\'+f(l.getUTCHours())+\':\'+f(l.getUTCMinutes())+\':\'+f(l.getUTCSeconds())+\'Z\'};Q.w.q=Number.w.q=Boolean.w.q=5(h){7 l.valueOf()}}x L=/[\\u0000\\14\\15-\\17\\18\\19\\1a\\1b-\\1c\\1d-\\1e\\1f-\\1g\\1h\\1i-\\1j]/g,M=/[\\\\\\"\\x00-\\x1f\\x7f-\\x9f\\14\\15-\\17\\18\\19\\1a\\1b-\\1c\\1d-\\1e\\1f-\\1g\\1h\\1i-\\1j]/g,8,C,1k={\'\\b\':\'\\\\b\',\'\\t\':\'\\\\t\',\'\\n\':\'\\\\n\',\'\\f\':\'\\\\f\',\'\\r\':\'\\\\r\',\'"\':\'\\\\"\',\'\\\\\':\'\\\\\\\\\'},o;5 N(p){M.1l=0;7 M.R(p)?\'"\'+p.D(M,5(a){x c=1k[a];7 6 c===\'p\'?c:\'\\\\u\'+(\'1m\'+a.1n(0).S(16)).1o(-4)})+\'"\':\'"\'+p+\'"\'}5 E(h,y){x i,k,v,e,G=8,9,2=y[h];3(2&&6 2===\'z\'&&6 2.q===\'5\'){2=2.q(h)}3(6 o===\'5\'){2=o.O(y,h,2)}switch(6 2){H\'p\':7 N(2);H\'U\':7 isFinite(2)?Q(2):\'I\';H\'boolean\':H\'I\':7 Q(2);H\'z\':3(!2){7\'I\'}8+=C;9=[];3(V.w.S.apply(2)===\'[z Array]\'){e=2.e;J(i=0;i<e;i+=1){9[i]=E(i,2)||\'I\'}v=9.e===0?\'[]\':8?\'[\\n\'+8+9.P(\',\\n\'+8)+\'\\n\'+G+\']\':\'[\'+9.P(\',\')+\']\';8=G;7 v}3(o&&6 o===\'z\'){e=o.e;J(i=0;i<e;i+=1){k=o[i];3(6 k===\'p\'){v=E(k,2);3(v){9.1p(N(k)+(8?\': \':\':\')+v)}}}}W{J(k in 2){3(V.1r.O(2,k)){v=E(k,2);3(v){9.1p(N(k)+(8?\': \':\':\')+v)}}}}v=9.e===0?\'{}\':8?\'{\\n\'+8+9.P(\',\\n\'+8)+\'\\n\'+G+\'}\':\'{\'+9.P(\',\')+\'}\';8=G;7 v}}3(6 m.X!==\'5\'){m.X=5(2,A,K){x i;8=\'\';C=\'\';3(6 K===\'U\'){J(i=0;i<K;i+=1){C+=\' \'}}W 3(6 K===\'p\'){C=K}o=A;3(A&&6 A!==\'5\'&&(6 A!==\'z\'||6 A.e!==\'U\')){1s 1t Error(\'m.X\');}7 E(\'\',{\'\':2})}}3(6 m.Y!==\'5\'){m.Y=5(B,11){x j;5 12(y,h){x k,v,2=y[h];3(2&&6 2===\'z\'){J(k in 2){3(V.1r.O(2,k)){v=12(2,k);3(v!==undefined){2[k]=v}W{delete 2[k]}}}}7 11.O(y,h,2)}L.1l=0;3(L.R(B)){B=B.D(L,5(a){7\'\\\\u\'+(\'1m\'+a.1n(0).S(16)).1o(-4)})}3(/^[\\],:{}\\s]*$/.R(B.D(/\\\\(?:["\\\\\\/bfnrt]|u[0-9a-fA-F]{4})/g,\'@\').D(/"[^"\\\\\\n\\r]*"|true|false|I|-?\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d+)?/g,\']\').D(/(?:^|:|,)(?:\\s*\\[)+/g,\'\'))){j=eval(\'(\'+B+\')\');7 6 11===\'5\'?12({\'\':j},\'\'):j}1s 1t SyntaxError(\'m.Y\');}}})();',[],92,'||value|if||function|typeof|return|gap|partial|||||length|||key||||this|JSON||rep|string|toJSON||||||prototype|var|holder|object|replacer|text|indent|replace|str||mind|case|null|for|space|cx|escapable|quote|call|join|String|test|toString||number|Object|else|stringify|parse|||reviver|walk|Date|u00ad|u0600||u0604|u070f|u17b4|u17b5|u200c|u200f|u2028|u202f|u2060|u206f|ufeff|ufff0|uffff|meta|lastIndex|0000|charCodeAt|slice|push||hasOwnProperty|throw|new'.split('|'),0,{}));








